#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

pthread_t ntid;
pthread_mutex_t mutex;
pthread_mutexattr_t attr;

void* thr_fn(void *arg){
	pthread_mutex_lock(&mutex);
	pthread_t tid=pthread_self();
	printf("thread %u,%x\n",tid,tid);
	pthread_mutex_unlock(&mutex);
}

int main(){
	int err;
	
	pthread_mutexattr_init(&attr);
	pthread_mutex_init(&mutex,&attr);
	
	err=pthread_create(&ntid,NULL,thr_fn,NULL);
	err=pthread_create(&ntid,NULL,thr_fn,NULL);	
	if(err!=0){
		fprintf(stderr,"thread craete error:%s\n",strerror(err));
		exit(1);
	}
	
	sleep(2);
}